﻿//打开字滑入效果
window.onload = function(){
	$(".connect p").eq(0).animate({"left":"0%"}, 600);
	$(".connect p").eq(1).animate({"left":"0%"}, 400);
};
//jquery.validate表单验证
$(document).ready(function(){
	//注册表单验证
	$("#registerForm").validate({
	    rules: {
	        Account: {
	            required: true,//必填
	            minlength: 3, //最少6个字符
	            maxlength: 32,//最多20个字符
	            remote: {
	                url: "/Manage/Register/IsExists",//用户名重复检查，别跨域调用
	                type: "post",
	                data: {
	                    Account: function () { return $("#account").val(); }
	                }
	            },
	        },
			Name:{
				required:true,//必填
				minlength:3, //最少6个字符
				maxlength:32,//最多20个字符				
			},
			Password:{
				required:true,
				minlength:6, 
				maxlength:32,
			},
			Email:{
				required:true,
				email:true,
			},
			confirm_password:{
				required:true,
				minlength:3,
				equalTo:'.password'
			},
			MobilePhone: {
				required:true,
				MobilePhone: true,//自定义的规则
				digits:true,//整数
			}
		},
		//错误信息提示
	    messages:{
	        Account:{
	                required:"必须填写账号",
	                minlength: "账号至少为3个字符",
	                maxlength: "账号至多为32个字符",
	                remote: "账号已存在",
	                },
			Name:{
				required:"必须填写真实姓名",
				minlength: "真实姓名至少为3个字符",
				maxlength: "真实姓名至多为32个字符",
			},
			Password:{
				required:"必须填写密码",
				minlength:"密码至少为6个字符",
				maxlength:"密码至多为32个字符",
			},
			Email:{
				required:"请输入邮箱地址",
				email: "请输入正确的email地址"
			},
			confirm_password:{
				required: "请再次输入密码",
				minlength: "确认密码不能少于3个字符",
				equalTo: "两次输入密码不一致",//与另一个元素相同
			},
			MobilePhone: {
				required:"请输入手机号码",
				digits:"请输入正确的手机号码",
			},
		
	    },
	    submitHandler: function (form) {
	        $.post("/Manage/Register/DoRegister", $(form).serialize(), function (rv) {
	            if (rv.State) {
	                Alert(rv.Message,function() {
	                    return window.location.href = "/Manage/Login/Index";
	                });	             
	            } else {
	                Alert(rv.Message, true);
	            }
	        });
	    }
	});
	//添加自定义验证规则
	jQuery.validator.addMethod("MobilePhone", function (value, element) {
		var length = value.length;
		var MobilePhone = /^1[3|4|5|8][0-9]\d{4,8}$/;
		return this.optional(element) || (length == 11 && MobilePhone.test(value));
	}, "手机号码格式错误"); 
});
